<template>
	<view class="my-content">
		<div class="set-btn" @click.stop="toSet()">编辑代理商信息</div>
		<div class="add-btn" @click.stop="toAdd()">添加</div>
		<view style="height: 80rpx;"></view>
		<view class="car-item" v-for="item in Lists" >
			<view style="width: 90%;display: flex;">
				<text>名称：{{ item.title }}</text>
				<image :src="imgDomain+item.logo"  style="width: 60rpx;height: 60rpx; margin-left: 20rpx;"></image>
			</view>
			<view style="width: 90%;display: flex;">
				<text>数量：{{ item.number }}</text>
				<text style=" margin-left: 20rpx;">进货价：{{ item.market_price }}元</text>
			</view>
			<view style="width: 90%;display: flex;">
				<text style=" margin-left: 0rpx;">进货时间：{{ item.create_at }}</text>
			</view>
			<div class="edit-btn" @click.stop="is_edit(item)">编辑</div>
			<div class="delete-btn" @click.stop="is_delete(item)">删除</div>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			Lists: [],
			imgDomain:'https://xcx.yumeishangmao.com/',
			member:{}
		}
	},
	onShow() {
		var member = uni.getStorageSync('member')
		if(member){
			this.member = member
			this.getList();
			
		}
	},
	methods: {
		toAdd() {
			if (!uni.getStorageSync('memberInfo')) {
				uni.showToast({
					'title':'请先登录'
				})
				return
			}
			uni.navigateTo({
				url: `/pages_tool/member/jinhuo_save`
			});
		},
		toSet() {
			if (!uni.getStorageSync('memberInfo')) {
				uni.showToast({
					'title':'请先登录'
				})
				return
			}
			uni.navigateTo({
				url: `/pages_tool/member/agent_save`
			});
		},
		is_edit(item) {
			if (!uni.getStorageSync('memberInfo')) {
				uni.showToast({
					'title':'请先登录'
				})
				return
			}
			uni.navigateTo({
				url: `/pages_tool/member/jinhuo_save?item=`+JSON.stringify(item)
			});
		},
		is_delete(item) {
			var that = this
			if (!uni.getStorageSync('memberInfo')) {
				uni.showToast({
					'title':'请先登录'
				})
				return
			}
			uni.showModal({
				title: '提示',
				content: '确定要删除吗？',
				success: (res) => {
					if (res.confirm) {
						that.$api.sendRequest({
							url: '/api/site/jinhuoDel', 
							data:{
								id: item.id
							},
							success: res => {
								that.Lists = res.data
							}
						})
						uni.showToast({
							title:'操作成功'
						})
						that.getList();
					}
				}
			});
		},
		getList() {
			var that = this
			uni.showLoading({
				title: '加载中...',
				mask: true
			});
			that.$api.sendRequest({
				url: '/api/site/jinhuoList', 
				data:{
					member_id :that.member.member_id
				},
				success: res => {
					that.Lists = res.data
				}
			})
			uni.hideLoading();
		}
	}
}
</script>

<style lang="less" scoped>
.delete-btn {
	position: absolute;
	right: 0;
	top: 0;
	background: red;
	color: #fff;
	padding: 10upx 20upx;
	border-radius: 10upx;
}
.edit-btn {
	position: absolute;
	right: 100rpx;
	top: 0;
	background: royalblue;
	color: #fff;
	padding: 10upx 20upx;
	border-radius: 10upx;
}
.add-btn {
	position: absolute;
	right: 0;
	top: 20rpx;
	background: orangered;
	color: #fff;
	padding: 10upx 20upx;
	border-radius: 10upx;
}
.set-btn {
	position: absolute;
	left: 0;
	top: 20rpx;
	background:royalblue;
	color: #fff;
	padding: 10upx 20upx;
	border-radius: 10upx;
}


.my-content {
	width: 100%;
	padding: 30upx;
	box-sizing: border-box;

	.car-item {
		width: 100%;
		background: #FFFBDB;
		border-radius: 16upx;
		align-items: center;
		padding: 36upx 40upx;
		position: relative;
		margin-bottom: 20upx;
		border: 2px solid #3662EC;
		box-sizing: border-box;

		text {
			font-size: 30upx;
			color: #FF8F1F;
			font-weight: 500;
			width: auto;
			text-align: center;
		}

	}
}
</style>